#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable:6031)

#include "Sort.h"

static void ArrPrint(const int* arr, const int size)
{
	int i = 0;
	for (i = 0; i < size; ++i)
	{
		printf("%d ", arr[i]);
	}

	printf("\n");
}

static void InsertSortTest(void)
{
	int arr[] = { 1,7,0,5,3,8,12,9,6,38,25,11,15,22 };
	int size = sizeof(arr) / sizeof(arr[0]);

	InsertSort(arr, size);
	ArrPrint(arr, size);
}

static void ShellSortTest(void)
{
	int arr[] = { 1,7,0,5,3,8,12,9,6,38,25,11,15,22 };
	int size = sizeof(arr) / sizeof(arr[0]);

	ShellSort(arr, size);
	ArrPrint(arr, size);
}

static void SelectSortTest(void)
{
	int arr[] = { 1,7,0,5,3,8,12,9,6,38,25,11,15,22 };
	int size = sizeof(arr) / sizeof(arr[0]);

	SelectSort(arr, size);
	ArrPrint(arr, size);
}

static void HeapSortTest(void)
{
	int arr[] = { 1,7,0,5,3,8,12,9,6,38,25,11,15,22 };
	int size = sizeof(arr) / sizeof(arr[0]);

	HeapSort(arr, size);
	ArrPrint(arr, size);
}

static void BubbleSortTest(void)
{
	int arr[] = { 1,7,0,5,3,8,12,9,6,38,25,11,15,22 };
	int size = sizeof(arr) / sizeof(arr[0]);

	BubbleSort(arr, size);
	ArrPrint(arr, size);
}

static void FastSortTest(void)
{
	int arr[] = { 1,7,0,5,3,8,12,9,6,38,25,11,15,22 };
	int size = sizeof(arr) / sizeof(arr[0]);

	FastSort(arr, 0, size - 1);
	ArrPrint(arr, size);
}

static void FastSortNonRTest(void)
{
	int arr[] = { 1,7,0,5,3,8,12,9,6,38,25,11,15,22 };
	int size = sizeof(arr) / sizeof(arr[0]);

	FastSortNonR(arr, 0, size - 1);
	ArrPrint(arr, size);
}


static void MergeSortTest(void)
{
	int arr[] = { 1,7,0,5,3,8,12,9,6,38,25,11,15,22 };
	int size = sizeof(arr) / sizeof(arr[0]);

	MergeSort(arr, size);
	ArrPrint(arr, size);
}

static void MergeSortNonRTest(void)
{
	int arr[] = { 1,7,0,5,3,8,12,9,6,38,25,11,15,22 };
	int size = sizeof(arr) / sizeof(arr[0]);

	MergeSortNonR(arr, size);
	ArrPrint(arr, size);
}

static void CountSortTest(void)
{
	int arr[] = { 1,7,0,5,3,8,12,9,6,38,25,11,15,22 };
	int size = sizeof(arr) / sizeof(arr[0]);

	CountSort(arr, size);
	ArrPrint(arr, size);
}

static void SortTest(void)
{
	srand((unsigned int)time(NULL));
	const int N = 100000;

	int* arr1 = (int*)malloc(sizeof(int) * N);
	int* arr2 = (int*)malloc(sizeof(int) * N);
	int* arr3 = (int*)malloc(sizeof(int) * N);
	int* arr4 = (int*)malloc(sizeof(int) * N);
	int* arr5 = (int*)malloc(sizeof(int) * N);
	int* arr6 = (int*)malloc(sizeof(int) * N);
	int* arr7 = (int*)malloc(sizeof(int) * N);
	int* arr8 = (int*)malloc(sizeof(int) * N);


	assert(arr1 && arr2 && arr3 && arr4 && arr5 && arr6 && arr7 && arr8 );

	int i = 0;
	for (i = 0; i < N; ++i)
	{
		arr1[i] = rand();
		arr2[i] = arr1[i];
		arr3[i] = arr1[i];
		arr4[i] = arr1[i];
		arr5[i] = arr1[i];
		arr6[i] = arr1[i];
		arr7[i] = arr1[i];
		arr8[i] = arr1[i];
	}

	//int i = 0;
	//for (i = 0; i < N; ++i)
	//{
	//	arr1[i] = i;
	//	arr2[i] = arr1[i];
	//	arr3[i] = arr1[i];
	//	arr4[i] = arr1[i];
	//	arr5[i] = arr1[i];
	//	arr6[i] = arr1[i];
	//}

	int begin1 = clock();
	InsertSort(arr1, N);
	int end1 = clock();
	printf("InsertSort:%d\n", end1 - begin1);

	int begin2 = clock();
	ShellSort(arr2, N);
	int end2 = clock();
	printf("ShellSort:%d\n", end2 - begin2);

	int begin3 = clock();
	SelectSort(arr3, N);
	int end3 = clock();
	printf("SelectSort:%d\n", end3 - begin3);

	int begin4 = clock();
	HeapSort(arr4, N);
	int end4 = clock();
	printf("HeapSort:%d\n", end4 - begin4);

	int begin5 = clock();
	BubbleSort(arr5, N);
	int end5 = clock();
	printf("BubbleSort:%d\n", end5 - begin5);

	int begin6 = clock();
	FastSort(arr6, 0, N-1);
	int end6 = clock();
	printf("FastSort:%d\n", end6 - begin6);

	int begin7 = clock();
	MergeSort(arr7,N);
	int end7 = clock();
	printf("MergeSort:%d\n", end7 - begin7);

	int begin8 = clock();
	CountSort(arr8, N);
	int end8 = clock();
	printf("CountSort:%d\n", end8 - begin8);

	free(arr1);
	free(arr2);
	free(arr3);
	free(arr4);
	free(arr5);
	free(arr6);
	free(arr7);
	free(arr8);
}

int main()
{
	//InsertSortTest();
	//ShellSortTest();
	//SelectSortTest();
	//HeapSortTest();
	//BubbleSortTest();
	//FastSortTest();
	//FastSortNonRTest();
	//MergeSortTest();
	//MergeSortNonRTest();
	//MergeSortFile("Data.txt");
	//CountSortTest();

	SortTest();
	return 0;
}

//int main()
//{
//	int a = 10;
//	int b = 5;
//	int c = (a & b) + ((a ^ b) >> 1);
//	printf("%d\n", c);
//	printf("%d\n", (a + b) / 2);
//	return 0;
//}

